package com.action.listBox;

import javax.swing.*;

public class ListComboBox extends AbstractListModel implements ComboBoxModel {
    private String[] nations = null;
    private String item=null;   //保存选项内容

    public String[] getNations() {
        return nations;
    }

    public void setNations(String[] nations) {
        this.nations = nations;
    }

    /**
     * 设置选项内容
     * @param anItem 选项内容
     */
    @Override
    public void setSelectedItem(Object anItem) {
        this.item=(String)anItem;
    }

    /**
     *
     * @return 返回选项
     */
    @Override
    public Object getSelectedItem() {
        return this.item;
    }

    /**
     *
     * @return 获取选项长度
     */
    @Override
    public int getSize() {
        return this.nations.length;
    }

    /**
     * 根据编号获取选项
     * @param index 编号
     * @return 选项
     */
    @Override
    public Object getElementAt(int index) {
        return this.nations[index];
    }
}
